home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / NEGATOR.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  1KB  |  43 lines

  1.  #include<functional>
  2.  #include<algorithm>
  3.  
  4.  using namespace std;
  5.  
  6.  //
  7.  // Create a new predicate from unary_function.
  8.  //
  9.  template<class Arg>
  10.  class is_odd : public unary_function<Arg, bool>
  11.  {
  12.    public:
  13.    bool operator() (const Arg& arg1) const
  14.    {
  15.      return (arg1 % 2 ? true : false);
  16.    }
  17.  };
  18.  
  19.  int main ()
  20.  {
  21.    less<int> less_func;
  22.    //
  23.    // Use not2 on less.
  24.    //
  25.    cout << (less_func(1,4) ? "TRUE" : "FALSE") << endl;
  26.    cout << (less_func(4,1) ? "TRUE" : "FALSE") << endl;
  27.    cout << (not2(less<int>())(1,4) ? "TRUE" : "FALSE") << endl;
  28.    cout << (not2(less<int>())(4,1) ? "TRUE" : "FALSE") << endl;
  29.    //
  30.    // Create an instance of our predicate.
  31.    //
  32.    is_odd<int> odd;
  33.    //
  34.    // Use not1 on our user defined predicate.
  35.    //
  36.    cout << (odd(1) ? "TRUE" : "FALSE") << endl;
  37.    cout << (odd(4) ? "TRUE" : "FALSE") << endl;
  38.    cout << (not1(odd)(1) ? "TRUE" : "FALSE") << endl;
  39.    cout << (not1(odd)(4) ? "TRUE" : "FALSE") << endl;
  40.  
  41.    return 0;
  42.  }
  43.